Imports System.ComponentModel
Imports System.Xml.Serialization
Imports Aricie.DNN.UI.Attributes
Imports Aricie.DNN
Imports Aricie.ComponentModel
Imports Aricie.DNN.UI.WebControls
Imports DotNetNuke.UI.WebControls
Imports Aricie.DNN.UI.WebControls.EditControls
Imports DotNetNuke.UI.Skins.Controls

Namespace Aricie.DNN.Caching.Analysis
    <Serializable()> _
    Public Class StatisticsSettings

        Private _StatisticsFileName As String = "Aricie.DistributedCaching.Stats.xml"
        Private _UpdateExistingStats As Boolean = True
        Private _MinSampleNumber As Integer = 3
        Private _MinSampleDeviation As Integer = 25
        Private _MaxSampleDeviation As Integer = 400
        Private _MinSequenceRatioToBest As Integer = 9
        Private _MinSequenceRatioForGraph As Integer = 20
        Private _MaxSequenceDuration As New STimeSpan(TimeSpan.FromMilliseconds(250))



        <ExtendedCategory("Results")> _
        Public Property ShowResults() As Boolean

        Private _Statistics As CacheStatistics

        <ConditionalVisible("ShowResults")> _
        <ExtendedCategory("Results")> _
        <XmlIgnore()> _
        Public Property Statistics As CacheStatistics
            Get
                If _Statistics Is Nothing AndAlso ShowResults Then
                    _Statistics = DistributedCachingBusinessController.LoadStatistics()
                End If
                Return _Statistics
            End Get
            Set(value As CacheStatistics)

            End Set
        End Property

        <ExtendedCategory("Results")> _
        <ActionButton(IconName.Magic, IconOptions.Normal, "ComputeStatistics.Warning")> _
        Public Overridable Sub ComputeStatistics(pe As AriciePropertyEditorControl)

            DistributedCachingBusinessController.BuildStatsFromLogs(DistributedCachingProviderBase.Settings, DistributedCachingBusinessController.LoadStatistics())
            ShowResults = True
            pe.ItemChanged = True
            pe.DisplayLocalizedMessage("StatisticsComputed.Message", ModuleMessage.ModuleMessageType.GreenSuccess)
        End Sub

        <ConditionalVisible("ShowResults")> _
        <ExtendedCategory("Results")> _
        <ActionButton(IconName.FloppyO, IconOptions.Normal, "ComputeAnalysis.Warning")> _
        Public Overridable Sub SaveStatistics(pe As AriciePropertyEditorControl)

            DistributedCachingBusinessController.SaveStatistics(Statistics)
            _Statistics = Nothing

            pe.ItemChanged = True
            pe.DisplayLocalizedMessage("StatisticsSaved.Message", ModuleMessage.ModuleMessageType.GreenSuccess)
        End Sub

        <ConditionalVisible("ShowResults")> _
       <ExtendedCategory("Results")> _
       <ActionButton(IconName.TrashO, IconOptions.Normal, "ComputeAnalysis.Warning")> _
        Public Overridable Sub ClearStatistics(pe As AriciePropertyEditorControl)
            _Statistics = New CacheStatistics
            pe.DisplayLocalizedMessage("StatisticsCleared.Message", ModuleMessage.ModuleMessageType.GreenSuccess)
            Me.SaveStatistics(pe)
        End Sub



        <ExtendedCategory("Settings")> _
            <Required(True)> _
        Public Property StatisticsFileName() As String
            Get
                Return _StatisticsFileName
            End Get
            Set(ByVal value As String)
                _StatisticsFileName = value
            End Set
        End Property

        <ExtendedCategory("Settings")> _
        Public Property UpdateExistingStats() As Boolean
            Get
                Return _UpdateExistingStats
            End Get
            Set(ByVal value As Boolean)
                _UpdateExistingStats = value
            End Set
        End Property

        <ExtendedCategory("Settings")> _
            <Required(True)> _
        Public Property MinSampleNumber() As Integer
            Get
                Return _MinSampleNumber
            End Get
            Set(ByVal value As Integer)
                _MinSampleNumber = value
            End Set
        End Property

        <ExtendedCategory("Settings")> _
            <Required(True)> _
         Public Property MinSampleDeviation() As Integer
            Get
                Return _MinSampleDeviation
            End Get
            Set(ByVal value As Integer)
                _MinSampleDeviation = value
            End Set
        End Property

        <ExtendedCategory("Settings")> _
            <Required(True)> _
         Public Property MaxSampleDeviation() As Integer
            Get
                Return _MaxSampleDeviation
            End Get
            Set(ByVal value As Integer)
                _MaxSampleDeviation = value
            End Set
        End Property

        <ExtendedCategory("Settings")> _
            <Required(True)> _
         Public Property MinSequenceRatioToBest() As Integer
            Get
                Return _MinSequenceRatioToBest
            End Get
            Set(ByVal value As Integer)
                _MinSequenceRatioToBest = value
            End Set
        End Property

        <ExtendedCategory("Settings")> _
            <Required(True)> _
        Public Property MinSequenceRatioForGraph() As Integer
            Get
                Return _MinSequenceRatioForGraph
            End Get
            Set(ByVal value As Integer)
                _MinSequenceRatioForGraph = value
            End Set
        End Property


        <ExtendedCategory("Settings")> _
         Public Property MaxSequenceDuration() As STimeSpan
            Get
                Return _MaxSequenceDuration
            End Get
            Set(ByVal value As STimeSpan)
                _MaxSequenceDuration = value
            End Set
        End Property







    End Class
End Namespace